package com.neuosft.his.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.neuosft.his.entity.CommonResult;
import com.neuosft.his.entity.User;

@WebServlet("/u.do")
public class UserController extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
//		判断执行业务
		String action =  request.getParameter("action");
		if (action==null || action.trim().length()==0) {
			action = "xxx";
		}
//		执行业务
		switch (action) {
		case "login":
			doLogin(request,response);
			break;
		case "reg":
			doReg(request,response);
			break;
		case "modPwd":
			doModPwd(request,response);
			break;
		default:
			doDefault(request,response);
			break;
		}		
	}

	private void doDefault(HttpServletRequest request, HttpServletResponse response) {
		CommonResult result =  new  CommonResult();
		result.badRequest();
		request.setAttribute(CommonResult.RESULT, result);		
	}

	private void doModPwd(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub	
	}

	private void doReg(HttpServletRequest request, HttpServletResponse response) {
		User user = new User(); // 包裹 = 手机+辅材
		user.setUname("doReg");
		CommonResult result = new CommonResult(user);
		request.setAttribute("result", result);
		
	}

	private void doLogin(HttpServletRequest request, HttpServletResponse response) {
		User user = new User(); // 包裹 = 手机+辅材
		user.setUname("doLogin");
		CommonResult result = new CommonResult(user);
		request.setAttribute("result", result);
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}

}
